package cn.jawar.learn.web;

import cn.jawar.learn.pojo.DateDTO;
import cn.jawar.learn.pojo.UserDTO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.*;
import java.util.Date;

/**
 * @author dongyi
 */
@RestController
public class TestController {
    @GetMapping("test1")
    public UserDTO test1() {
        UserDTO userDTO = new UserDTO();
        userDTO.setName("dongs");
        userDTO.setAge(18);

        var day = LocalDate.of(2000, 1, 1);
        userDTO.setZonedDateTime(day.atStartOfDay(ZoneId.of("Z")));
        userDTO.setDefaultZonedDateTime(day.atStartOfDay(ZoneId.systemDefault()));
        userDTO.setLocalDateTime(day.atStartOfDay());
        userDTO.setDate(Date.from(userDTO.getZonedDateTime().toInstant()));
        userDTO.setDefaultDate(Date.from(userDTO.getDefaultZonedDateTime().toInstant()));
        userDTO.setNewDate(new Date());
        System.out.println("userDTO = " + userDTO);
        return userDTO;
    }

    @GetMapping("test2")
    public DateDTO test2() {

        var dateDTO = new DateDTO()
                .setDate(new Date())
                .setDay(LocalDate.now())
                .setTime(LocalTime.now())
                .setDateTime(LocalDateTime.now())
                .setInstant(Instant.now())
                .setUtc0(ZonedDateTime.now(ZoneId.of("Z")))
                .setUtcPlus8(ZonedDateTime.now(ZoneId.of("Asia/Shanghai")))
                .setSystemZoneId(ZoneId.systemDefault());
        System.out.println("dateDTO = " + dateDTO);
        return dateDTO;
    }

}
